#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

void* MyMemcpy(void* dest, const void* src, int num)
{
	assert(dest && src);
	void* ret = dest;
	while (num--)
	{
		*((char*)dest)++ = *((char*)src)++;
	}
	return ret;
}

void* MyMemmove(void* dest, void* src, int num)
{
	assert(dest && src);
	void* ret = dest;
	if (dest <= src)
	{
		while (num--)
		{
			*((char*)dest)++ = *((char*)src)++;
		}
	}
	else
	{
		dest = (char*)dest + num - 1;
		src = (char*)src + num - 1;
		while (num--)
		{
			*((char*)dest)-- = *((char*)src)--;
		}
	}
	return ret;
}

int main()
{
	int arr1[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
	int arr2[] = { 9, 8, 7, 6, 5, 4, 3 };
	//MyMemcpy(arr1, arr2, sizeof(arr2));
	MyMemmove(arr1 + 2, arr1, 16);
	for (int i = 0; i < 7; i++)
	{
		printf("%d ", arr1[i]);
	}
	printf("\n");
	return 0;
}